package com.example.t410.service.serviceImpl;

import com.example.t410.VO.KnowledgeVO;
import com.example.t410.entity.Knowledge;
import com.example.t410.mapper.*;
import com.example.t410.service.KnowledgeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class KnowledgeServiceImpl implements KnowledgeService {
    @Autowired
    KnowledgeMapper knowledgeMapper;
    @Autowired
    ContentMapper contentMapper;
    @Autowired
    ImagelistMapper imagelistMapper;
    @Autowired
    SatrlinepicMapper satrlinepicMapper;
    @Autowired
    TitleiconMapper titleiconMapper;


    /**
     * 知识科普查询
     * @return
     */
    @Override
    public List<KnowledgeVO> selectAll() {
        List<KnowledgeVO> list=new ArrayList<>();
        List<Knowledge> knowledgeList=knowledgeMapper.selectAll();
        for(Knowledge knowledge:knowledgeList){
            KnowledgeVO k=new KnowledgeVO();
            BeanUtils.copyProperties(knowledge,k);
            Long id=knowledge.getId();
            k.setContent(contentMapper.selectByKnowledgeId(id));
            k.setImageList(imagelistMapper.selectByKnowledgeId(id));
            k.setStarLinePic(satrlinepicMapper.selectByKnowledgeId(id));
            k.setTitleIcon(titleiconMapper.selectById(knowledge.getTitleIconId()));
            list.add(k);
        }
        return list;
    }
}
